// subpkg_worker/my/modifyIdentity/modifyIdentity.js
import Dialog from '@vant/weapp/dialog/dialog';
import Toast from '@vant/weapp/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    beadhouse:'',
    beadhouseList: [
    ],
    value1:-1,
  },

  changebeadhouse1(e){
     var index = e.detail
     console.log(index)
     const that = this
     var beadhouse = this.data.beadhouseList[index].text
     Dialog.confirm({
      title: '标题',
      message: `你确定绑定"${beadhouse}"吗？`,
    })
      .then(() => {
       
        // on confirm
        
        wx.request({
          url: `https://zhixiao.site:8080/msg-bind-care-home/send-request?userId=${wx.getStorageSync('userid')}&careHomeName=${beadhouse}`,
          method:'POST',
          header:{
            'Content-Type':'application/json'
          },
          success:(res)=>{
            console.log(res)
          },
          complete:(res)=>{
            Dialog.alert({
              message: '信息审核中',
            }).then(() => {
              // on close
              wx.navigateTo({
                url: '/pages/elderList/elderList',
              })

            });
          }
        })
      })
      .catch(() => {
        that.setData({
          value1:-1
        })
        // on cancel
      });
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.request({
      url: 'https://zhixiao.site:8080/client/nurse/query',
      data:{
        userId:wx.getStorageSync('userid')
      },
      success:(res)=>{
       
        var careHomeName = res.data.data.careHomeName
        this.setData({
          beadhouse:careHomeName
        })
      }
    })
    wx.request({
      url: 'https://zhixiao.site:8080/client/home/name/query',
      success:(res)=>{
        var beadhouseList1 = res.data.data
        console.log(res.data.data)
        var beadhouseList = this.data.beadhouseList
        for(var i=0;i<beadhouseList1.length;i++){
          beadhouseList.push({text:beadhouseList1[i].name,value:i})
        }
        this.setData({
          beadhouseList:beadhouseList
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})